package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.method.Method;
import com.azier.kapacitor.util.CollectionUtil;
import com.azier.kapacitor.script.arg.*;
import com.azier.kapacitor.script.method.*;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

<#if noteEn??>
/**
${noteEn!}
**/
</#if>
<#if note??>
/**
${note!}
**/
</#if>
public class ${nodeName!}Node extends AbstractNode {
    private static final String name = "${nodeName?uncap_first}";

    public ${nodeName!}Node(<#if args??&&(args?size>0)><#list args as arg><#if arg.timeArg??&&arg.timeArg==1>long interval, String durationLiteral<#else >${arg.type!} <#if arg.isList??&&arg.isList==1>...</#if>${arg.name?uncap_first}</#if><#if arg_has_next>, </#if></#list></#if>) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        <#if args??&&(args?size>0)>
        <#list args as arg>
        //<#--如Quite-->
    <#if arg.isList??&&arg.isList==1>
        for(${arg.type!} argf : ${arg.name?uncap_first}){
        this.args.add(new ${arg.convertType!}(argf));
        }
    <#else>
        this.args.add(new ${arg.convertType!}(${arg.name?uncap_first}));
    </#if>
        </#list>
        </#if>
    }

    <#if methods??&&(methods?size>0)>
    <#list methods as method>
        <#if method.noteEn??>
    /**
    ${method.noteEn!}
    **/
        </#if>
        <#if method.note??>
    /**
    ${method.note!}
    **/
        </#if>
    public ${nodeName!}Node ${method.name?uncap_first}(<#if method.args??&&(method.args?size>0)><#list method.args as arg><#if arg.timeArg??&&arg.timeArg==1>long interval, String durationLiteral<#else >${arg.type!} <#if arg.isList??&&arg.isList==1>...</#if>${arg.name?uncap_first}</#if><#if arg_has_next>, </#if></#list></#if>){
        ${method.name} ${method.name?uncap_first} = new ${method.name}(<#if method.args??&&(method.args?size>0)><#list method.args as arg><#if arg.timeArg??&&arg.timeArg==1>interval, durationLiteral<#else >${arg.name?uncap_first}</#if><#if arg_has_next>, </#if></#list></#if>);
        super.addMethod(${method.name?uncap_first});
        return this;
    }
    </#list>
    </#if>


/** ------------------------------------------------ **/
/** 链接节点  **/
/** ------------------------------------------------ **/
<#if nodes??&&(nodes?size>0)>
<#list nodes as node>
    <#if node.noteEn??>
    /**
    ${node.noteEn!}
    **/
    </#if>
    <#if node.note??>
    /**
    ${node.note!}
    **/
    </#if>
    public ${node.nodeName}Node ${node.nodeName?uncap_first}(<#if node.args??&&(node.args?size>0)><#list node.args as arg><#if arg.timeArg??&&arg.timeArg==1>long interval, String durationLiteral<#else >${arg.type!} <#if arg.isList??&&arg.isList==1>...</#if>${arg.name?uncap_first}</#if><#if arg_has_next>, </#if></#list></#if>){
        ${node.nodeName}Node nextNode = new ${node.nodeName}Node(<#if node.args??&&(node.args?size>0)><#list node.args as arg><#if arg.timeArg??&&arg.timeArg==1>interval, durationLiteral<#else >${arg.name?uncap_first}</#if><#if arg_has_next>, </#if></#list></#if>);
        this.nextNode = nextNode;
        nextNode.zetHeadNode(this.headNode);
        return nextNode;
    }
</#list>
</#if>

/** 未能写出的节点 **/

<#if notFound??&&(notFound?size>0)>
    <#list notFound as no>
        //${no!}<#if no_has_next>, </#if>
    </#list>
</#if>

}